package com.education.basic.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.education.basic.dao.FeeInfoDAO;
import com.education.basic.entity.FeeInfo;
import com.yunshangwoniu.core.baseDao.impl.BaseDaoImpl;
import com.yunshangwoniu.core.utils.Logger;

@Component("feeInfoDAO")
public class FeeInfoDAOImpl extends BaseDaoImpl<FeeInfo> implements FeeInfoDAO 
{

	@Override
	public FeeInfo getByStuNum(String stuNum) 
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "From FeeInfo info where info.stuNo=?";
		Query q  = session.createQuery(hql);
		q.setString(0, stuNum);
		try
		{
			FeeInfo info = (FeeInfo)q.uniqueResult();
			Logger.debug(this.getClass(), String.format("get feeInfo success by [stuNum:%s]", stuNum));
			return info;
		}catch(Exception e)
		{
			Logger.debug(this.getClass(), String.format("get feeInfo fail by [stuNum:%s]", stuNum));
			return null;
		}
	}

	@Override
	public FeeInfo getByStudentName(String studnentName) 
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "From FeeInfo info where info.studentName=?";
		Query q  = session.createQuery(hql);
		q.setString(0, studnentName);
		try
		{
			FeeInfo info = (FeeInfo)q.uniqueResult();
			Logger.debug(this.getClass(), String.format("get feeInfo success by [studnentName:%s]", studnentName));
			return info;
		}catch(Exception e)
		{
			Logger.debug(this.getClass(), String.format("get feeInfo fail by [studnentName:%s]", studnentName));
			return null;
		}
	}
	
}
